/*
Package service
@Time : 2022/12/21 17:19
@Author : 董胜烨
@File : overtime
@Software: GoLand
@note:
*/
package service

import (
	"employee/model"
	"fmt"
)

type Overtime struct {
	Date       string  `json:"date"`
	EmployeeID int64   `json:"employee_id"`
	HourlyWage float64 `json:"hourly_wage"`
	ID         int64   `json:"id"`
	Time       float64 `json:"time"`
}

func (o *Overtime) Insert() bool {
	sqlStr := "INSERT INTO overtime (employee_id, date, time, hourly_wage) VALUES (?,?,?,?)"
	insertId := model.Insert(sqlStr, o.EmployeeID, o.Date, o.Time, o.HourlyWage)
	if insertId == 0 {
		return false
	}
	o.ID = insertId
	return true
}

func (o Overtime) Update() bool {
	sqlStr := "UPDATE overtime SET employee_id=?,date=?,time=?,hourly_wage=? WHERE id=?"
	ok := model.Update(sqlStr, o.EmployeeID, o.Date, o.Time, o.HourlyWage, o.ID)
	return ok
}

func (o Overtime) Delete() bool {
	sqlStr := "DELETE FROM overtime WHERE id=?"
	ok := model.Delete(sqlStr, o.ID)
	return ok
}

func (o Overtime) QueryByEmployee() []map[string]string {
	sqlStr := fmt.Sprintf("SELECT * FROM overtime WHERE employee_id='%d'", o.EmployeeID)
	res := model.QueryAll(sqlStr)
	return res
}
